package Test02;

import java.util.ArrayList;

public class CarTest {
    public static void main(String[] args) {

        ArrayList<Car> cars = new ArrayList<>();
        cars.add(new Car("宝马", "黑色", 500000));
        cars.add(new Car("奔驰", "红色", 300000));
        cars.add(new Car("奥迪", "红色", 200000));
        for (int i = 0; i < cars.size(); i++) {
            //遍历集合，将颜色为“红色”的汽车按照如下格式打印到控制台上。
            if ("红色".equals(cars.get(i).getColor())) {
                System.out.println(cars.get(i).getBrand() + "-" +
                        cars.get(i).getColor() + "-" +
                        cars.get(i).getPrice());
            }
        }
    }
}
